<?php
/*
 * 车主圈编辑
 * @arrange WL
 * @package ixdcw
 * @file    owners.inc.php
 * @time    12-12-19 上午11:01
 */
defined('IN_IXDCW') or exit('Access Denied');

login();
if(!check_group($_groupid, '5')) {
	Prompt::message('对不起，只有个人会员才可以加入车主圈', url('owners/index'));
}

require DT_CORE.'/'.$module.'/common.inc.php';
require_once DT_INC.'/post.func.php';
$do = new OwnersModule($moduleid);
$do->setUsername($_username);
$item = $do->getOne();

switch($action) {
	case 'car':
	if($submit) {
		if($do->pass($post)) {
			$do->edit($post);
			Prompt::tip('资料编辑成功', '?action='.$action);
		}else{
			Prompt::alert($do->getErrmsg(),'?action=car');
		}
	}
	break;
	case 'addcar':
		if($submit) {
			if($do->pass($post)) {
				$do->add($post);
				Prompt::tip('车型添加成功', '?action=likecar&tab=1');
			}else{
				Prompt::alert($do->getErrmsg(),'?action=addcar&tab=1');
			}
		}
	break;
	case 'editcar':
		$itemid or Prompt::message();
		$do->setItemid($itemid);
		$items = $do->getOne_likecar();
		if(!$items || $items['username'] != $_username) Prompt::message();
		if($MG['edit_limit'] < 0) Prompt::message($L['edit_refuse']);
		if($MG['edit_limit'] && $DT_TIME - $item['addtime'] > $MG['edit_limit']*86400) Prompt::message(lang($L['edit_limit'], array($MG['edit_limit'])));
		if($submit) {
			if($do->pass($post)) {
					$do->editcar($post);
					Prompt::tip('车型修改成功', '?action=likecar&tab=1');
				}else{
				    Prompt::alert($do->getErrmsg(),'?action=editcar&tab=1');
				}
		} else {
				extract($item);
			}
	break;
	case 'likecar':
		$lists = $do->getList_likecar();
		foreach($lists as $k=>$v){
			$lists[$k]['brand'] = AutoBrand::get($v['arbid']);
			$lists[$k]['car'] = AutoCar::get($v['arcid']);
			$lists[$k]['model'] = AutoModel::get($v['amid']);
		}
	break;
	case 'delcar':
		$itemid or msg('请选择'.$MOD['name']);
		 $do->delcar($itemid);
		Prompt::tip('删除成功', $forward);
		break;

}

include template('owners', 'member');